﻿<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:local="clr-namespace:TaskDialogInterop"
	x:Class="TaskDialogInterop.TaskDialog"
	mc:Ignorable="d"
	d:DesignWidth="495"
	d:DataContext="{d:DesignData Source=DesignData/DesignerTaskDialogViewModel.xaml}"
	Title="{Binding Title, Mode=OneWay}"
	ResizeMode="NoResize"
	ShowInTaskbar="False"
	SizeToContent="WidthAndHeight"
	MaxWidth="500"
	MinWidth="375"
	SnapsToDevicePixels="True"
	TextOptions.TextFormattingMode="Display">

	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="ResourceDictionaries/Common.xaml"/>
			</ResourceDictionary.MergedDictionaries>
			<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
			<local:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter"/>
			<BitmapImage x:Key="ExpArrUp1" UriSource="Resources/exparr-up1.bmp" />
			<BitmapImage x:Key="ExpArrUp2" UriSource="Resources/exparr-up2.bmp" />
			<BitmapImage x:Key="ExpArrUp3" UriSource="Resources/exparr-up3.bmp" />
			<BitmapImage x:Key="ExpArrDown1" UriSource="Resources/exparr-down1.bmp" />
			<BitmapImage x:Key="ExpArrDown2" UriSource="Resources/exparr-down2.bmp" />
			<BitmapImage x:Key="ExpArrDown3" UriSource="Resources/exparr-down3.bmp" />
			<BitmapImage x:Key="ExpArr1" UriSource="Resources/exparr-down1.bmp" />
			<BitmapImage x:Key="ExpArr2" UriSource="Resources/exparr-down2.bmp" />
			<BitmapImage x:Key="ExpArr3" UriSource="Resources/exparr-down3.bmp" />
		</ResourceDictionary>
	</Window.Resources>

	<Grid x:Name="LayoutRoot">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>
		<Border x:Name="ContentArea" Padding="7,3,7,7" Background="White">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="1*" />
				</Grid.ColumnDefinitions>
				<Image x:Name="MainIcon"
					   Source="{Binding MainIcon, Mode=OneWay}"
					   Margin="3,7,7,8" VerticalAlignment="Top"
					   Width="32" Height="32"
					   Visibility="{Binding MainIcon, Converter={StaticResource NotNullToVisibilityConverter}, Mode=OneWay}" />
				<Grid Grid.Column="1">
					<Grid.Resources>
						<Style TargetType="{x:Type TextBlock}">
							<Setter Property="TextWrapping" Value="Wrap"/>
						</Style>
					</Grid.Resources>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>
					<TextBlock x:Name="MainInstruction"
							   Text="{Binding MainInstruction, Mode=OneWay}"
							   FontSize="16" Margin="3,7,5,3"
							   Foreground="#FF0033B3"
							   Visibility="{Binding MainInstruction, Converter={StaticResource NotNullToVisibilityConverter}, Mode=OneWay}"/>
					<TextBlock x:Name="ContentText" Grid.Row="1"
							   Margin="3,12,3,8"
							   Visibility="{Binding Content, Converter={StaticResource NotNullToVisibilityConverter}, Mode=OneWay}" />
					<TextBlock x:Name="ContentExpandedInfo" Grid.Row="2"
							   Margin="3,0,3,8"
							   Visibility="{Binding ContentExpandedInfoVisible, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" />
					<ProgressBar x:Name="ProgressBar" Grid.Row="3"
								 Height="15" Margin="3,7,3,3"
								 Value="{Binding ProgressBarValue, Mode=OneWay}"
								 Minimum="{Binding ProgressBarMinimum, Mode=OneWay}"
								 Maximum="{Binding ProgressBarMaximum, Mode=OneWay}"
								 IsIndeterminate="{Binding ProgressBarIndeterminate, Mode=OneWay}"
								 Visibility="{Binding ShowProgressBar, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"/>
					<ItemsControl x:Name="CommandLinks" Grid.Row="4"
								  Margin="4,17,11,3"
								  ItemsSource="{Binding CommandLinks}"
								  ItemsPanel="{DynamicResource ItemsPanelTemplate}"
								  ItemTemplate="{DynamicResource DataTemplate}">
						<ItemsControl.Resources>
							<ItemsPanelTemplate x:Key="ItemsPanelTemplate">
								<StackPanel/>
							</ItemsPanelTemplate>
							<DataTemplate x:Key="DataTemplate">
								<local:CommandLink Click="CommandLink_Click"/>
							</DataTemplate>
						</ItemsControl.Resources>
					</ItemsControl>
					<ItemsControl x:Name="RadioButtons" Grid.Row="4"
								  Margin="10,15,10,6"
								  ItemsSource="{Binding RadioButtons}"
								  ItemsPanel="{DynamicResource ItemsPanelTemplate}"
								  ItemTemplate="{DynamicResource DataTemplate}">
						<ItemsControl.Resources>
							<ItemsPanelTemplate x:Key="ItemsPanelTemplate">
								<StackPanel/>
							</ItemsPanelTemplate>
							<DataTemplate x:Key="DataTemplate">
								<RadioButton Margin="3,3,3,4"
											 GroupName="default"
											 Content="{Binding Text, Mode=OneWay}"
											 IsChecked="{Binding IsDefault, Mode=OneWay}"
											 Command="{Binding Command, Mode=OneWay}"
											 CommandParameter="{Binding ID, Mode=OneWay}"/>
							</DataTemplate>
						</ItemsControl.Resources>
					</ItemsControl>
				</Grid>
			</Grid>
		</Border>
		<Border x:Name="ButtonsArea" Grid.Row="1"
				BorderThickness="0,1,0,0" Padding="9,6"
				Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
				BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="1*"/>
				</Grid.ColumnDefinitions>
				<StackPanel Orientation="Vertical">
					<ToggleButton x:Name="ShowDetailsButton"
								  Margin="1,3,0,3" HorizontalAlignment="Left"
								  Visibility="{Binding HasExpandedInfo, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
								  Template="{DynamicResource ButtonControlTemplate}"
								  IsChecked="{Binding ExpandedInfoVisible, Mode=TwoWay}">
						<ToggleButton.Resources>
							<ControlTemplate x:Key="ButtonControlTemplate" TargetType="{x:Type ToggleButton}">
								<StackPanel Orientation="Horizontal" Background="Transparent">
									<Image x:Name="ShowDetailsArrow"
										   Source="{DynamicResource ExpArrDown1}"
										   Stretch="None" Width="19" Height="19"
										   VerticalAlignment="Center" HorizontalAlignment="Left"
										   UseLayoutRounding="True"
										   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
									<TextBlock x:Name="ShowDetailsLabel"
											   Text="Show details"
											   Margin="8,0,0,0"
											   HorizontalAlignment="Left" VerticalAlignment="Center"/>
								</StackPanel>
								<ControlTemplate.Triggers>
									<MultiTrigger>
										<MultiTrigger.Conditions>
											<Condition Property="IsChecked" Value="False"/>
											<Condition Property="IsMouseOver" Value="True"/>
										</MultiTrigger.Conditions>
										<Setter TargetName="ShowDetailsArrow" Property="Source" Value="{DynamicResource ExpArrDown2}"/>
									</MultiTrigger>
									<MultiTrigger>
										<MultiTrigger.Conditions>
											<Condition Property="IsChecked" Value="False"/>
											<Condition Property="IsPressed" Value="True"/>
										</MultiTrigger.Conditions>
										<Setter TargetName="ShowDetailsArrow" Property="Source" Value="{DynamicResource ExpArrDown3}"/>
									</MultiTrigger>
									<Trigger Property="IsChecked" Value="True">
										<Setter TargetName="ShowDetailsArrow" Property="Source" Value="{DynamicResource ExpArrUp1}"/>
										<Setter TargetName="ShowDetailsLabel" Property="Text" Value="Hide details"/>
									</Trigger>
									<Trigger Property="IsChecked" Value="False">
										<Setter TargetName="ShowDetailsLabel" Property="Text" Value="Show details"/>
									</Trigger>
									<MultiTrigger>
										<MultiTrigger.Conditions>
											<Condition Property="IsChecked" Value="True"/>
											<Condition Property="IsMouseOver" Value="True"/>
										</MultiTrigger.Conditions>
										<Setter TargetName="ShowDetailsArrow" Property="Source" Value="{DynamicResource ExpArrUp2}"/>
									</MultiTrigger>
									<MultiTrigger>
										<MultiTrigger.Conditions>
											<Condition Property="IsChecked" Value="True"/>
											<Condition Property="IsPressed" Value="True"/>
										</MultiTrigger.Conditions>
										<Setter TargetName="ShowDetailsArrow" Property="Source" Value="{DynamicResource ExpArrUp3}"/>
									</MultiTrigger>
								</ControlTemplate.Triggers>
							</ControlTemplate>
						</ToggleButton.Resources>
					</ToggleButton>
					<CheckBox x:Name="VerificationCheckBox"
							  Margin="4,3"
							  Visibility="{Binding VerificationText, Converter={StaticResource NotNullToVisibilityConverter}, Mode=OneWay}"
							  HorizontalAlignment="Left" MaxWidth="215"
							  IsChecked="{Binding VerificationChecked, Mode=TwoWay}">
						<CheckBox.Content>
							<TextBlock Text="{Binding VerificationText, Mode=OneWay}"
									   TextWrapping="Wrap" VerticalAlignment="Top"
									   Margin="7,0,0,0"/>
						</CheckBox.Content>
					</CheckBox>
				</StackPanel>
				<ItemsControl x:Name="Buttons" Grid.Column="1"
							  ItemsSource="{Binding NormalButtons}"
							  ItemsPanel="{DynamicResource ButtonsItemsPanelTemplate}"
							  ItemTemplate="{DynamicResource ButtonsDataTemplate}">
					<ItemsControl.Resources>
						<ItemsPanelTemplate x:Key="ButtonsItemsPanelTemplate">
							<WrapPanel Orientation="Horizontal" HorizontalAlignment="Right"/>
						</ItemsPanelTemplate>
						<DataTemplate x:Key="ButtonsDataTemplate">
							<Button Content="{Binding Text}"
									Margin="4,3" Padding="12,1"
									MinWidth="66" MinHeight="21"
									Command="{Binding Command, Mode=OneWay}"
									CommandParameter="{Binding ID, Mode=OneWay}"
									IsCancel="{Binding IsCancel, Mode=OneWay}"
									IsDefault="{Binding IsDefault, Mode=OneWay}"
									Click="NormalButton_Click"
                                    Foreground="Black"
                                    Style="{x:Null}"/>
						</DataTemplate>
					</ItemsControl.Resources>
				</ItemsControl>
			</Grid>
		</Border>
		<Border x:Name="FooterArea" Grid.Row="2"
				BorderThickness="0,1,0,0"
				Visibility="{Binding FooterText, Converter={StaticResource NotNullToVisibilityConverter}, Mode=OneWay}"
				Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
				BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
			<Border x:Name="FooterInner"
					BorderThickness="0,1,0,0" Padding="9"
					BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto" />
						<ColumnDefinition Width="1*" />
					</Grid.ColumnDefinitions>
					<Image x:Name="FooterIcon"
						   Source="{Binding FooterIcon, Mode=OneWay}"
						   VerticalAlignment="Top"
						   Width="16" Height="16" Margin="3,0"/>
					<TextBlock x:Name="FooterText" Grid.Column="1" Margin="4,0" TextWrapping="Wrap"/>
				</Grid>
			</Border>
		</Border>
		<Border x:Name="FooterExpandedArea" Grid.Row="3"
				BorderThickness="0,1,0,0"
				Visibility="{Binding FooterExpandedInfoVisible, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}"
				Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
				BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
			<Border x:Name="FooterExpandedInner"
					BorderThickness="0,1,0,0" Padding="9"
					BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}">
				<TextBlock x:Name="FooterExpandedInfo" Margin="4,0" TextWrapping="Wrap"/>
			</Border>
		</Border>
	</Grid>
</Window>
